#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"

void STInit(struct stack* ST)
{
	assert(ST);
	ST->arr = (struct stack*)malloc(sizeof(struct stack)*5);
	ST->top = 0;
	ST->capacity = 5;
}
void STDestroy(struct stack* ST)
{
	assert(ST);
	free(ST->arr);
	ST->arr = NULL;
	ST->top = 0;
	ST->capacity = 0;
}

void STPop(struct stack* ST)
{
	assert(ST);
	assert(!STEmpty(ST));
	ST->top--;
}
void STPush(struct stack* ST, StackDataType x)
{
	assert(ST);
	if (ST->top == ST->capacity)
	{
		struct stack* tmp = (struct stack*)realloc(ST, sizeof(struct stack) * ST->capacity * 2);
		if (tmp == NULL)
		{
			perror("STPush");
		}
		ST->capacity *= 2;
	}
	ST->arr[ST->top] = x;
	ST->top++;
}
bool STEmpty(struct stack* ST)
{
	return ST->top == 0;
}

StackDataType STTop(struct stack* ST)
{
	assert(ST);
	assert(!STEmpty(ST));
	return ST->arr[ST->top - 1];
}

int STSize(struct stack* ST)
{
	assert(ST);
	return ST->top;
}